package com.gyd.nosql;
import com.mongodb.Mongo;

import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.DBCursor;
import com.mongodb.ServerAddress;

import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class Connection {

	Mongo m;
	DB db;
	
	public boolean conectar(){
		try {
			m = new Mongo("localhost", 27017);
			db = m.getDB( "martedb" );
			return true;
		} catch (UnknownHostException e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public DBCursor simpleQuery(String collection,List<String> column, List<String> value){
		
		DBCollection col = db.getCollection(collection);
		BasicDBObject searchQuery = new BasicDBObject();
		if(column.size()==value.size()){
			for(int i=0;i<column.size(); i++){
				searchQuery.put(column.get(i),value.get(i));	
			}
			
		}
		DBCursor cursor = col.find(searchQuery);
		return cursor;
	}
	
}
